// shengchangongxuLocal.js 生产工序本地存储操作工具，包含工序信息的增删查改等方法
const STORAGE_KEY = 'shengchangongxu';

export function getGongxuList() {
  return JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
}

export function saveGongxuList(list) {
  localStorage.setItem(STORAGE_KEY, JSON.stringify(list));
}

export function addGongxu(item) {
  const list = getGongxuList();
  item.id = Date.now();
  list.push(item);
  saveGongxuList(list);
}

export function updateGongxu(item) {
  const list = getGongxuList();
  const idx = list.findIndex(i => i.id === item.id);
  if (idx !== -1) {
    list[idx] = item;
    saveGongxuList(list);
  }
}

export function deleteGongxu(ids) {
  let list = getGongxuList();
  list = list.filter(i => !ids.includes(i.id));
  saveGongxuList(list);
}

export function getGongxuById(id) {
  return getGongxuList().find(i => i.id === id);
} 